let uid = 0;
// 依赖收集
class Dep{
    constructor() {
        this.id = uid++;
        this.subs = []; // 存放当前属性对应的watcher
    }
    // 进入watcher中收集dep(相互收集)
    depend() {
        if(Dep.target) {
            Dep.target.addDep(this)
            // this.subs.push(Dep.target) 会造成重复收集
        }
    }
    // 添加watcher
    addSub(watcher) {
        this.subs.push(watcher)
    }

    // 通知watcher更新
    notify() {
        this.subs.forEach(watcher => watcher.update())
    }
}

export default Dep;